package com.sanchunhui.psc.utils.bleuitls.request

import android.util.Log
import com.sanchunhui.psc.utils.bleuitls.callback.OnReceiverCallback


import java.util.HashMap

/**
 * 描述:接收通知数据请求队列
 */
class ReceiverRequestQueue : IRequestQueue<OnReceiverCallback> {
    var map = HashMap<String, OnReceiverCallback>()
        internal set

    override operator fun set(key: String, onReceiver: OnReceiverCallback) {
        map[key] = onReceiver
    }

    override operator fun get(key: String): OnReceiverCallback {
        return map[key]!!
    }

    /**
     * 移除一个元素
     *
     * @param key
     */
    fun removeRequest(key: String): Boolean {
        Log.d(TAG, "ReceiverRequestQueue before:" + map.size)
        val onReceiverCallback = map.remove(key)
        Log.d(TAG, "ReceiverRequestQueue after:" + map.size)
        return null == onReceiverCallback
    }

    companion object {
        private val TAG = "ReceiverRequestQueue"
    }
}
